package com.ning.action;

import org.apache.struts2.ServletActionContext;

import com.ning.dao.UserDao;
import com.ning.pojo.User;
import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport {
	
	/**
	 * 登录
	 * @return
	 * @throws Exception
	 */
	public String login() throws Exception{
		User user1 = userDao.getUserByLoginName(user.getLoginName());
		if(null == user1){
			result = "登录名或密码错误";
			return "login";
		}
		if(!user.getPassword().equals(user1.getPassword())){
			result = "登录名或密码错误";
			return "login";
		}
		ServletActionContext.getRequest().getSession().setAttribute("user", user1);
		if(1 == user1.getType()){
			return "competent";
		}else if(2 == user1.getType()){
			return "manager";
		}else if(3 == user1.getType()){
			return "boss";
		}
		return SUCCESS;
	}
	
	/**
	 * 登出
	 * @return
	 * @throws Exception
	 */
	public String logout() throws Exception{
		ServletActionContext.getRequest().getSession().setAttribute("user", null);
		return "logout";
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	private UserDao userDao;
	private User user;
	private String result;
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
}
